<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script src="axios.js"></script>
  <script>
    axios.interceptors.request.use(function (config) {
      // 在数据发送之前，做这里写一些事情
      console.log("发送之前");
      console.log(config);
      config.headers['aaaa']="12233456";
      return config;
    }, function (error) {
      //出错了
      return Promise.reject(error);
    });

    // 添加一个响应的拦截
    axios.interceptors.response.use(function (response) {
      // 响应之前 
      console.log("响应拦截");
      console.log(response);
      // response.data = null;
      return response;
    }, function (error) {
      return Promise.reject(error);
    });

    axios.get("mock/data.json").then(res=>{
      console.log(res)
    }).catch();
  </script>
</body>

</html>